package com.sczmgk.hotline_pzh.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.gson.Gson;
import com.linkrenhe.frame.http.Tools;
import com.sczmgk.hotline_pzh.MyApp;
import com.sczmgk.hotline_pzh.R;
import com.sczmgk.hotline_pzh.base.BaseActivity;
import com.sczmgk.hotline_pzh.callback.SimplePaserJsonCallback;
import com.sczmgk.hotline_pzh.constants.Constants;
import com.sczmgk.hotline_pzh.entity.OpinionBean;
import com.sczmgk.hotline_pzh.httputils.MyHttp;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/1 0001.
 */
public class OnlineComplaintsActivity extends BaseActivity {

    private static final int REQUEST_CODE = 20;
    private TextView mProcedureCentent;
    private Button mBtnNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_online_complaint);
        setHeader() ;
        initView() ;
        initData() ;
        setListener() ;
    }

    /**
     * 设置头
     */
    private void setHeader() {
        setTitle(R.string.online_complaint);
        setLeftBtnVisibility(View.VISIBLE);
    }

    /**
     * 初始化控件
     */
    private void initView() {
        //投诉须知的内容
        mProcedureCentent = (TextView) findViewById(R.id.tv_online_procedure_centent);
        //下一步的按钮
        mBtnNext = (Button) findViewById(R.id.btn_online_next);
    }

    /**
     * 初始化数据
     */
    private void initData() {

        Map<String,Object> maps = new HashMap<>();
        maps.put("imei", MyApp.imei);
        MyHttp.requestByCommon(Constants.BASE_URL + Constants.GET_COMPLAINT_NOTES, maps, MyHttp.GET, OnlineComplaintsActivity.this, true, null, new SimplePaserJsonCallback() {
            @Override
            public void onVerifyIsNull() {

            }

            @Override
            public void onVerifySuccess(String dataRaw, boolean isCache) {

                Gson gson = new Gson();
                final OpinionBean opinionBean = gson.fromJson(dataRaw, OpinionBean.class);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(!Tools.isEmpty(opinionBean.content)){

                            mProcedureCentent.setText(opinionBean.content);
                        }
                    }
                });
            }
        });
    }

    /**
     * 设置监听
     */
    private void setListener() {

        //下一步的点击事件
        mBtnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                UIUtils.startActivity(OnlineComplaintsActivity.this , OnlineComplaintDetailActivity.class);
                Intent intent = new Intent(OnlineComplaintsActivity.this , OnlineComplaintDetailActivity.class) ;
                startActivityForResult(intent , REQUEST_CODE);
            }
        });
    }

    @Override
    public void handleMessage(Message msg) {

    }

    @Override
    public boolean getIsNeedLogin() {
        return true;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent arg2) {
        super.onActivityResult(requestCode, resultCode, arg2);
        if (resultCode == RESULT_OK){
            if (requestCode == REQUEST_CODE){
                setResult(RESULT_OK ,arg2);
                finish();
            }
        }
    }
}
